import {createApp} from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// import ElementUI from 'element-ui';
// import 'element-ui/lib/theme-chalk/index.css';
import installElementPlus from './plugins/element'
import './assets/css/icon.css'
// import preventReClick from './store/preventReClick'//防多次点击，重复提交
// import qs from 'qs'
import axios from 'axios'
// Vue.prototype.$ajax=axios
// Vue.prototype.$qs=qs
const app = createApp(App)
// router.beforeEach((to, from, next) => {
// // ...
//     console.log(to)
//     console.log(from)
//     console.log(next)
// })
//导航守卫
// 请求拦截
axios.interceptors.request.use(

    config => {
    // 判断是否存在token，如果存在的话，则每个http header都加上token
      let token = localStorage.getItem("TOKEN")
       console.log(token)
      // console.log(!config.headers.hasOwnProperty('Authorization') )
      if (!config.headers.hasOwnProperty('Authorization') && token) {
        config.headers = {
            'X-Access-Token': token
            }
      }
      return config;
    },
    error => {
      return Promise.reject(error);
    });

  // 响应拦截  判断token失效跳转
  axios.interceptors.response.use(response =>{
    // console.log(response.status)
    if(response.status == '500'){
      localStorage.removeItem('TOKEN')
      this.$router.push('/login')
    }
    return response;
  },error =>{
    alert("登录失效，请重新登录！")
    router.push('/login')
    return Promise.reject(error)//返回接口返回的错误信息
    
  })
installElementPlus(app)
    app
    .use(store)
    .use(router)
    // .use(ElementUI)
    .mount('#app')
    .$http(axios)
    // .use(preventReClick)
    